package com.acme.service.bank.impl;

import com.acme.domain.account.Account;
import com.acme.domain.account.CheckingAccount;
import com.acme.domain.account.SavingAccount;
import com.acme.domain.bank.Bank;
import com.acme.domain.bank.Client;
import com.acme.domain.bank.Gender;
import com.acme.exceptions.NoEnoughFundsException;
import com.acme.service.bank.BankCannotBeLoadedException;
import com.acme.service.bank.BankLoader;

import java.math.BigDecimal;

public class DummyBankLoader implements BankLoader {
    @Override
    public Bank load() throws BankCannotBeLoadedException {
        Bank bank = new Bank();
        try {
            Client client1 = new Client("John", Gender.MALE);
            Account account1 = new SavingAccount(new BigDecimal(100));
            Account account2 = new CheckingAccount(new BigDecimal(100), new BigDecimal(150));
            client1.addAccount(account1);
            client1.addAccount(account2);
            bank.addClient(client1);

            Client client2 = new Client("Miranda", Gender.FEMALE);
            Account account3 = new SavingAccount(new BigDecimal(50));
            Account account4 = new CheckingAccount(new BigDecimal(75), new BigDecimal(20));
            client2.addAccount(account3);
            client2.addAccount(account4);
            bank.addClient(client2);

            account1.withdraw(new BigDecimal(30));
            account2.withdraw(new BigDecimal(200));
            account4.withdraw(new BigDecimal(70));

            try {
                account4.withdraw(new BigDecimal(10));
            } catch (NoEnoughFundsException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            throw new BankCannotBeLoadedException(e);
        }
        return bank;
    }
}